home *** CD-ROM | disk | FTP | other *** search
- /******************************************************************************
- *
- * NSSDC/CDF CDFwalk. Part 2 of 2.
- *
- * Version 1.0, 3-Mar-92, ST Systems (STX)
- *
- * Modification history:
- *
- * V1.0 25-Jul-91, H Leckner Original version.
- *
- ******************************************************************************/
-
- #include "wfl.h"
-
- #include <stdio.h>
- #include <math.h>
- #include <string.h>
- #include <ctype.h>
-
- #if defined(unix)
- #include <sys/types.h>
- #include <sys/stat.h>
- extern char *getenv();
- #else
- #if defined (vms)
- #include <descrip.h>
- #else
- #if defined(__MSDOS__)
- #include <dos.h>
- #endif
- #endif
- #endif
-
- #include "cdfdist.h"
- #include "kb_def.h"
- #include "utility.h"
- #include "cdfwalk.h"
-
- void CDFWALK_load_discrete(values, num_values, num_bytes, DIS_display,
- num_rows, num_cols)
- char values[];
- long int num_values;
- long int num_bytes;
- struct vid_struct *DIS_display;
- int *num_rows;
- int *num_cols;
- {
- /*long int temp_rows;*/
- long int i;
- for (i=0; i<num_values; i++)
- {
- DIS_display[i].row = 1;
- DIS_display[i].col = 1;
- strcpy(DIS_display[i].label,&values[i*num_bytes]);
- }
-
- *num_rows = num_values+ROW_OFFSET > DIS_ROWS ? DIS_ROWS : num_values+ROW_OFFSET;
-
- *num_cols = num_bytes+COL_OFFSET-1 < DIS_COLUMNS ? num_bytes+COL_OFFSET-1 : DIS_COLUMNS;
- }
- void CDFWALK_get_EPOCH(CDF_id, var_num, max_record_num,
- bin_values, char_values)
- long int CDF_id;
- long int var_num;
- long int max_record_num;
- double bin_values[];
- char *char_values;
- {
- long int indices[CDF_MAX_DIMS];
- long int counts[CDF_MAX_DIMS];
- long int intervals[CDF_MAX_DIMS];
- long int record_num;
- long int recInterval;
- long int i;
- CDFstatus rcode;
- extern char *epochString();
-
- for (i=0; i < CDF_MAX_DIMS; i++)
- {
- indices[i] = 0;
- counts[i] = 1;
- intervals[i] = 1;
- }
- record_num = 0;
- recInterval = 1;
- rcode = CDFvarHyperGet(CDF_id, var_num, record_num, max_record_num+1,
- recInterval, indices, counts, intervals, bin_values);
- if(rcode == CDF_OK)
- {
- for (record_num=0; record_num <= max_record_num; record_num++)
- {
- ep.tSince0 = bin_values[record_num];
- strcpy(&char_values[record_num*EPOCH_WIDTH], epochString(&ep));
- }
- }
- }
- void CDFWALK_get_discrete(CDF_id, dim_num, var_id, data_type, num_values,
- bin_values, char_values)
- long int CDF_id;
- long int dim_num;
- long int var_id;
- long int data_type;
- long int num_values;
- double bin_values[];
- char *char_values;
- {
- long int indices[10];
- char temp_val[MINMAX_SIZE+1];
- long int i;
- /*long int len;*/
- long int record_num;
- CDFstatus rcode;
- union mixed temp;
- double r4_r8();
-
- record_num = 0;
- for (i=0; i < 10; i++)
- indices[i] = 0;
- for (i=0; i < num_values; i++)
- {
- if(dim_num > 0)
- indices[dim_num-1]=i;
- else
- record_num = i;
- switch(data_type)
- {
- case CDF_REAL4:
- case CDF_FLOAT:
- rcode = CDFvarGet(CDF_id, var_id, record_num,
- indices, &temp.r4);
- bin_values[i] = r4_r8(&temp.r4);
- if(bin_values[i] < -1.e12 ||
- bin_values[i] > 1.e12)
- sprintf(temp_val,"%e",bin_values[i]);
- else
- sprintf(temp_val,"%f",bin_values[i]);
- break;
- case CDF_REAL8:
- case CDF_DOUBLE:
- case CDF_EPOCH:
- rcode = CDFvarGet(CDF_id, var_id, record_num,
- indices, &temp.r8);
- if(temp.r8 < -1.e12 ||
- temp.r8 > 1.e12)
- sprintf(temp_val,"%e",temp.r8);
- else
- sprintf(temp_val,"%f",temp.r8);
- bin_values[i] = temp.r8;
- break;
- case CDF_INT4:
- rcode = CDFvarGet(CDF_id, var_id, record_num,
- indices, &temp.i4);
- sprintf(temp_val,"%ld",temp.i4);
- bin_values[i] = (double) temp.i4;
- break;
- case CDF_UINT4:
- rcode = CDFvarGet(CDF_id, var_id, record_num,
- indices, &temp.ui4);
- sprintf(temp_val,"%lu",temp.ui4);
- bin_values[i] = (double) temp.ui4;
- break;
- case CDF_INT2:
- rcode = CDFvarGet(CDF_id, var_id, record_num,
- indices, &temp.i2);
- sprintf(temp_val,"%d",temp.i2);
- bin_values[i] = (double) temp.i2;
- break;
- case CDF_UINT2:
- CDFvarGet(CDF_id, var_id, record_num,
- indices, &temp.ui2);
- sprintf(temp_val,"%u",temp.ui2);
- bin_values[i] = (double) temp.ui2;
- break;
- case CDF_BYTE:
- case CDF_INT1:
- rcode = CDFvarGet(CDF_id, var_id, record_num,
- indices, &temp.byte);
- sprintf(temp_val,"%d",temp.byte);
- bin_values[i] = (double) temp.byte;
- break;
- case CDF_UINT1:
- rcode = CDFvarGet(CDF_id, var_id, record_num,
- indices, &temp.ubyte);
- sprintf(temp_val,"%u",temp.ubyte);
- bin_values[i] = (double) temp.ubyte;
- }
- if(rcode == CDF_OK)
- {
- temp_val[MINMAX_SIZE-1] = '\0';
- zero_replace(temp_val);
- strcpy(&char_values[i*MINMAX_SIZE], temp_val);
- }
- }
- }
- void CDFWALK_get_discrete_char(CDF_id, dim_num, var_num, num_values,
- num_bytes, char_values)
- long int CDF_id;
- long int dim_num;
- long int var_num;
- long int num_values;
- long int num_bytes;
- char *char_values;
- {
- char *temp;
- long int indices[10];
- long int i;
- long int record_num;
- CDFstatus rcode;
- temp = (char *) malloc(num_bytes+1);
- record_num = 0;
- for (i=0; i < 10; i++)
- indices[i] = 0;
- for (i=0; i < num_values; i++)
- {
- indices[dim_num-1] = i;
- rcode = CDFvarGet(CDF_id, var_num, record_num, indices, temp);
- if(rcode == CDF_OK)strcpy(&char_values[i*(num_bytes+1)], temp);
- }
- free (temp);
- }
- void CDFWALK_clear_row(vid, display, start_elem, end_elem, end_col)
- WINDOWid vid;
- struct vid_struct display[];
- int start_elem;
- int end_elem;
- int end_col;
- {
- long int i;
- int len;
-
- int row, col;
-
- for (i=start_elem; i<=end_elem; i++)
- {
- len = strlen(display[i-1].label);
- row = display[i-1].row;
- col = display[i-1].col + len;
- erase_display(vid, row, col, row, end_col);
- }
- }
- void CDFWALK_help(screen)
- struct GLOBAL_struct *screen;
- {
- long int dummy;
- struct vid_struct *HELP_display;
- long int help_num_elements = 0;
- long int i, len;
- int tcode;
- static char help_mes[] = "Press Return key when done";
- static char help_error_mes[] = "Help not available ";
- static char help_error_mal[] = "Help not available, malloc error ";
- char key_line1[KEY_COLUMNS-COL_OFFSET+1]; /* V1.5 */
- char key_line2[KEY_COLUMNS-COL_OFFSET+1]; /* V1.5 */
- char temp[80];
- int help_rows, help_columns, paste_col;
- int max_len;
- static first = TRUE;
- if(HELP_ptr != NULL)
- {
- /*
- READ text until complete and load into a vid structure
- */
- max_len = 0;
- fseek(HELP_ptr, 0l, SEEK_SET);
- while (fgets(temp,80,HELP_ptr) != NULL)
- {
- help_num_elements++;
- len = lastc(temp);
- if(len > max_len)max_len = len;
- }
- if(help_num_elements > HELP_ROWS)
- help_rows = HELP_ROWS;
- else
- help_rows = help_num_elements+ROW_OFFSET;
-
- if(max_len > HELP_COLUMNS)
- help_columns = HELP_COLUMNS;
- else
- help_columns = max_len+COL_OFFSET;
-
- paste_col = (80-help_columns)/2+1;
-
- if(first)
- create_virtual_display(help_rows, help_columns, &S.HELP_vid, BORDER, BOLD);
- first = FALSE;
-
- HELP_display = (struct vid_struct *)
- malloc(help_num_elements * sizeof(struct vid_struct));
- if(HELP_display == NULL)
- {
- CDFWALK_put_message(S.MES_vid, help_error_mal, RINGBELL, NORMAL,
- NOPAUSE);
- return;
- }
- fseek(HELP_ptr, 0l, SEEK_SET);
- i=0;
- for(i=0; i <help_num_elements; i++)
- {
- fgets(temp,80,HELP_ptr);
- HELP_display[i].row = 1;
- HELP_display[i].col = 1;
- len = lastc(temp) - 1;
- strncpy(HELP_display[i].label,temp,len);
- HELP_display[i].label[len] = '\0';
- }
- /*
- LOAD in the keypad definitions for this option
- */
- key_line1[0] = '\0'; key_line2[0] = '\0';
- strcat(key_line1, UP); strcat(key_line1,PUP);
- strcat(key_line2, DOWN);strcat(key_line2,PDOWN);
- strcat(key_line2,CNTRLW);
- CDFWALK_load_keydef(S.KEY_vid, key_line1, key_line2);
- CDFWALK_put_message(S.MES_vid, help_mes, NOBELL, NORMAL, NOPAUSE);
- /*
- Display the HELP screen
- */
- CDFWALK_select_menu_item(S.HELP_vid, S.MES_vid,
- &dummy, HELP_display, help_num_elements, help_rows, help_columns,
- HELP_ROW_PASTE, paste_col, HELP_MENU, &tcode);
- free(HELP_display);
- }
- else
- CDFWALK_put_message(S.MES_vid, help_error_mes, RINGBELL, NORMAL, NOPAUSE);
- }
- int lastc(buf)
- char *buf;
- {
- int done = FALSE;
- int i,j;
- int end;
- i = strlen(buf) + 1;
- end = i;
- j = 0;
- while(j < end && !done)
- {
- if(!isgraph(buf[i-1]))
- done = TRUE;
- else
- j++; i--;
- }
- return(i);
- }
-
- void CDFWALK_field_menu(screen, option)
- struct GLOBAL_struct *screen;
- long int *option;
- {
- int tcode, cont;
- long int temp;
- /*char key_line1[KEY_COLUMNS-COL_OFFSET+1];*/
- /*char key_line2[KEY_COLUMNS-COL_OFFSET+1];*/
- /*long int flag;*/
- temp = *option+1;
- cont = CONTINUE;
- while(cont != DONE)
- {
- /*
- Choose the particular field you wish to be in
- */
- CDFWALK_Menu_keydef(screen);
- CDFWALK_select_menu_item(S.FIELD_vid, S.MES_vid, &temp,
- FIELD_display, FIELD_NUM_ELEMENTS, FIELD_ROWS, FIELD_COLUMNS,
- FIELD_ROW_PASTE, FIELD_COL_PASTE, MENU, &tcode);
- *option = temp-1;
- if(*option == HELP_FIELD)
- CDFWALK_help(screen);
- else
- cont = DONE;
- }
- }
-
- void CDFWALK_open_screen(screen)
- struct GLOBAL_struct *screen;
- {
- create_pasteboard();
- #if defined(vms)
- begin_pasteboard_update();
- #endif
- create_virtual_display(CDF_ROWS, CDF_COLUMNS, &S.CDF_vid, BORDER, BOLD);
- paste_virtual_display(S.CDF_vid, CDF_ROW_PASTE, CDF_COL_PASTE);
- #if defined(unix)
- begin_display_update(S.CDF_vid);
- #endif
- load_vid(S.CDF_vid, CDF_display, 0, CDF_NUM_ELEMENTS-1, NO_label);
- #if defined(unix)
- end_display_update(S.CDF_vid);
- #endif
- create_virtual_display(VAR_ROWS, VAR_COLUMNS, &S.VAR_vid, BORDER, BOLD);
- paste_virtual_display(S.VAR_vid, VAR_ROW_PASTE, VAR_COL_PASTE);
- create_virtual_display(KEY_ROWS, KEY_COLUMNS, &S.KEY_vid, BORDER, BOLD);
- paste_virtual_display(S.KEY_vid, KEY_ROW_PASTE, MES_COL_PASTE);
- create_virtual_display(MES_ROWS, MES_COLUMNS, &S.MES_vid, BORDER, BOLD);
- paste_virtual_display(S.MES_vid, MES_ROW_PASTE, MES_COL_PASTE);
- create_virtual_display(VARSCROLL_ROWS, VARSCROLL_COLUMNS, &S.VARSCROLL_vid,
- BORDER, BOLD);
- create_virtual_display(FIELD_ROWS, FIELD_COLUMNS, &S.FIELD_vid,
- BORDER, BOLD);
- create_virtual_display(DIS_ROWS, DIS_COLUMNS, &S.DIS_vid, BORDER, BOLD);
- create_virtual_display(DIM_ROWS, DIM_COLUMNS, &S.DIM_vid, BORDER, BOLD);
- create_virtual_display(DIR_ROWS, DIR_COLUMNS, &S.DIR_vid, BORDER, BOLD);
-
- #if defined(vms)
- end_pasteboard_update();
- enable_trap(S.MES_vid);
- #endif
- load_vid(S.KEY_vid, KEY_display, 0, KEY_NUM_ELEMENTS, KEY_label);
- load_vid(S.MES_vid, MES_display, 0, MES_NUM_ELEMENTS, MES_label);
- }
- #if defined(unix) | defined(ultrix) | defined(__MSDOS__)
- void CDFWALK_draw_main_screen(screen, WALK, EPOCH)
- struct GLOBAL_struct *screen;
- long int WALK;
- long int EPOCH;
- {
- repaste_virtual_display(S.CDF_vid, CDF_ROW_PASTE, CDF_COL_PASTE);
- repaste_virtual_display(S.VAR_vid, VAR_ROW_PASTE, VAR_COL_PASTE);
- repaste_virtual_display(S.KEY_vid, KEY_ROW_PASTE, KEY_COL_PASTE);
- label_border(S.KEY_vid, KEY_label, strlen(KEY_label));
- repaste_virtual_display(S.MES_vid, MES_ROW_PASTE, MES_COL_PASTE);
- label_border(S.MES_vid, MES_label, strlen(MES_label));
- if(WALK)
- {
- repaste_virtual_display(S.WALK_vid, WALK_ROW_PASTE, WALK_COL_PASTE);
- if(!EPOCH)
- label_border(S.WALK_vid, WALK_label,strlen(WALK_label));
- else
- label_border(S.WALK_vid, WALK_EPOCH_label, strlen(WALK_EPOCH_label));
- }
- }
- #endif
- void CDFWALK_select_menu_item(vid, MES_vid, rvalue, display,
- num_elements, num_rows, num_columns, row_start, col_start, mode, termcode)
- WINDOWid vid;
- WINDOWid MES_vid;
- long int *rvalue;
- struct vid_struct display[];
- int num_elements;
- int num_rows;
- int num_columns;
- int row_start;
- int col_start;
- int mode;
- int *termcode;
- {
- int in_value;
- int row, col;
- int tcode;
- int done;
- int num_screen;
- int start_page;
- int end;
- int value;
- int row1 = 1;
- int col1 = 1;
- static char top[] = "Top of menu";
- static char bottom[] = "Bottom of menu";
-
- in_value = *rvalue;
- /*
- Find out the number of rows to be on the screen at one time
- */
- num_rows = num_rows - ROW_OFFSET;
- num_columns = num_columns - COL_OFFSET;
- if(num_elements > num_rows)
- num_screen = num_rows;
- else
- num_screen = num_elements;
- /*
- Erase and load data into the menu for selection
- */
- value = 1;
- row = 1;
- col = 1;
- #if defined(unix) | defined(ultrix) | defined(__MSDOS__)
- begin_display_update(vid);
- #endif
- erase_display(vid, 1, 1, num_rows, num_columns);
- load_menu(vid, display, num_screen, NO_label);
- change_rendition(vid,1,1,num_rows,num_columns,NORMAL);
- paste_virtual_display(vid, row_start, col_start);
- #if defined(unix) | defined(ultrix) | defined(__MSDOS__)
- end_display_update(vid);
- #endif
- start_page = 1;
- if(mode == MENU)change_rendition(vid, row, col, 1, num_columns, REVERSE);
- done = FALSE;
- while(!done)
- {
- set_cursor_abs(vid, row, col);
- #ifdef vms
- read_input(&tcode);
- #endif
- #if defined(unix) | defined(ultrix) | defined(__MSDOS__)
- read_input(vid, &tcode);
- #endif
- switch (tcode)
- {
- case KB_DOWNARROW:
- if(row == num_rows || value == num_elements)
- if(value < num_elements)
- {
- /*
- SCROLL UP
- */
- value++; start_page++;
- begin_display_update(vid);
- erase_display(vid, row1, col1, num_rows, num_columns);
- load_menu(vid, display+(start_page-1),
- num_screen, NO_label);
- end_display_update(vid);
- }
- else
- {
- value = 1;
- row = 1;
- start_page = 1;
- begin_display_update(vid);
- erase_display(vid, 1, 1, num_rows, num_columns);
- load_menu(vid, display, num_screen, NO_label);
- end_display_update(vid);
- }
- else
- {
- row++; value++;
- }
- break;
- case KB_UPARROW:
- if(row > 1)
- {
- row--;
- value--;
- }
- else if(value > 1)
- {
- /*
- SCROLL DOWN
- */
- value--; start_page--;
- begin_display_update(vid);
- erase_display(vid, row1, col1, num_rows, num_columns);
- load_menu(vid, display+(start_page-1),
- num_screen, NO_label);
- end_display_update(vid);
- }
- else
- {
- start_page = num_elements - num_screen + 1;
- value = num_elements;
- row = num_screen;
- begin_display_update(vid);
- erase_display(vid, row1, col1, num_rows, num_columns);
- load_menu(vid, display+(start_page-1),
- num_screen, NO_label);
- end_display_update(vid);
- }
- break;
- /*
- PAGE DOWN
- */
- case PAGEdown:
- case PAGEDOWN:
- start_page = start_page + num_screen;
- end = start_page + num_screen - 1;
- value = value + num_screen;
- if(end > num_elements)
- {
- /*
- Display the next page down
- */
- end = num_elements;
- start_page = end - num_screen + 1;
- value = num_elements;
- row = num_rows;
- CDFWALK_put_message(MES_vid, bottom, NOBELL, NORMAL, NOPAUSE);
- }
- begin_display_update(vid);
- erase_display(vid, row1, col1, num_rows, num_columns);
- load_menu(vid, display+(start_page-1), num_screen, NO_label);
- end_display_update(vid);
- break;
- /*
- PAGE UP
- */
- case PAGEUP:
- case PAGEup:
- start_page = start_page - num_screen;
- value = value - num_screen;
- if(start_page < 1)
- {
- start_page = 1;
- value = 1;
- row = 1;
- CDFWALK_put_message(MES_vid, top, NOBELL, NORMAL, NOPAUSE);
- }
- begin_display_update(vid);
- /*
- Display the next page up
- */
- erase_display(vid, row1, col1, num_rows, num_columns);
- load_menu(vid, display+(start_page-1), num_screen, NO_label);
- end_display_update(vid);
- break;
- case KB_RETURN:
- case KB_PAD_ENTER:
- done = TRUE;
- *rvalue = value;
- *termcode = KB_RETURN;
- break;
- case QUIT:
- case quit:
- done = TRUE;
- *rvalue = in_value;
- *termcode = QUIT;
- break;
- case KB_CTRL_F:
- done = TRUE;
- *rvalue = value;
- *termcode = KB_CTRL_F;
- break;
- case KB_REDRAW:
- repaint_screen();
- break;
- default:
- break;
- }
- if(mode == MENU)
- {
- change_rendition(vid, 1, 1, num_rows, num_columns, NORMAL);
- change_rendition(vid, row, 1, 1, num_columns, REVERSE);
- }
- }
- unpaste_virtual_display(vid);
- }
- int CDFWALK_CDF_name(screen, CDF, field_num, input_type)
- struct GLOBAL_struct *screen;
- struct CDF_struct *CDF;
- long int *field_num;
- long int *input_type;
- {
- char file_spec[256],temp[256] /*, dummy[256]*/ ;
- static char save[CDF_PATHNAME_LEN];
- char save_name[CDF_PATHNAME_LEN];
- char save_temp[CDF_PATHNAME_LEN];
- char **directory_list;
- char **result_spec_list;
- int num_files = 0;
- int termcode, /*cont,*/ i, row;
- int drows;
- long int CDF_num;
- int tcode;
- int done;
- int dir;
- static int first = TRUE;
- char row_data[CDF_COLUMNS];
- #if defined(unix)
- static char curr_dir[] = "./*.cdf" ;
- #else
- #if defined(__MSDOS__)
- static char curr_dir[] = ".\\*.cdf";
- #else
- #if defined(vms)
- static char curr_dir[] = "[]*.cdf";
- #endif
- #endif
- #endif
-
- static char dir_mes[] =
- "Enter Directory and/or CDF name (default=CDFs in current directory)";
- static char dir_error[] = "No CDFs found, reenter directory and/or CDF name";
- static char select_mes[] =
- "Select a CDF or press Q to enter a new Directory/CDF_name";
- struct vid_struct *DIR_display;
- char key_line1[KEY_COLUMNS-COL_OFFSET+1]; /* V1.5 */
- char key_line2[KEY_COLUMNS-COL_OFFSET+1]; /* V1.5 */
- int new_CDF;
- int regfile;
- int last_error = FALSE;
- strcpy(save_name, C.CDF_name);
- new_CDF= FALSE;
- done = FALSE;
- regfile = FALSE;
- while(!done)
- {
- if(*input_type == MANUAL)
- {
- if(first)
- {
- key_line1[0] = '\0'; key_line2[0] = '\0';
- strcat(key_line1, CNTRLM); strcat(key_line1, RET);strcat(key_line1, CNTRLN);
- strcat(key_line2, CNTRLW);strcat(key_line2, HLP);
- strcat(key_line2, " ");strcat(key_line2, CNTRLD); /* V1.5 */
- CDFWALK_load_keydef(S.KEY_vid, key_line1, key_line2);
- if(!last_error)
- {
- for (i=0; i < CDF_NAME_LENGTH; i++)
- C.CDF_name[i] = '\0';
- strcpy(C.CDF_name, default_name);
-
- CDFWALK_put_selection(S.CDF_vid, CDF_display, 0,
- C.CDF_name, CDF_NAME_LENGTH-COL_OFFSET, REVERSE);
- }
- CDFWALK_put_message(S.MES_vid, dir_mes, NOBELL, NORMAL, NOPAUSE);
- input_field(S.CDF_vid, C.CDF_name,
- CDF_NAME_ROW, CDF_NAME_COL, CDF_NAME_LENGTH-COL_OFFSET, &termcode);
- }
- else
- CDFWALK_put_selection(S.CDF_vid, CDF_display, 0,
- save, CDF_NAME_LENGTH-COL_OFFSET, REVERSE);
- }
- else
- termcode = KB_RETURN;
- *input_type = MANUAL;
- first = FALSE;
- last_error = FALSE;
- CDFWALK_clear_row(S.MES_vid, MES_display, 1, 1, MES_COLUMNS-COL_OFFSET);
- if(termcode == KB_CTRL_F)
- {
- CDFWALK_field_menu(screen, field_num);
- if((int) (*field_num) != CDF_FIELD)
- {
- done = TRUE;
- tcode = QUIT;
- }
- else
- first = TRUE;
- }
- else
- {
- row = CDF_NAME_ROW;
-
- read_display(S.CDF_vid, row, row_data);
-
- for (i=CDF_NAME_COL; i < CDF_NAME_COL+CDF_NAME_LENGTH-1; i++)
- if(row_data[i-1] != 32)
- temp[i-CDF_NAME_COL] = row_data[i-1];
- else
- temp[i-CDF_NAME_COL] = '\0';
- /*
- Save for next time
- */
- strcpy(save_temp, temp);
-
- strcpy(file_spec, temp);
- if(strlen(file_spec) == 0)
- strcpy(file_spec, curr_dir);
- else
- {
- dir = FALSE;
- strcpy(temp, file_spec);
- strcat(temp,".cdf");
- if(!IsReg(temp))
- {
- regfile = FALSE;
- if(IsDir(file_spec))
- {
- AppendToDir(file_spec, "*.cdf");
- dir = TRUE;
- }
- else
- strcat(file_spec, ".cdf");
- }/* end else */
- else
- {
- regfile = TRUE;
- strcat(file_spec, ".cdf");
- }
- }/* end else */
- num_files = DirList(file_spec, &directory_list, &result_spec_list);
- if(num_files > 0)
- {
- strcpy(save, save_temp);
- RemoveExtensions(num_files, result_spec_list);
- done = TRUE;
- if(num_files == 1 && regfile)
- {
- CDF_num = 1;
- tcode = KB_RETURN;
- first = TRUE;
- }
- else
- {
- /*
- allocate the space for a vid structure which contains the CDF NAMES
- */
- DIR_display = (struct vid_struct *)
- malloc(num_files * sizeof(struct vid_struct));
- if(DIR_display == NULL)return(BAD_MALLOC);
- /*
- Load in the cdf names into the structure
- */
- for (i=0; i<num_files; i++)
- {
- DIR_display[i].row = 1;
- DIR_display[i].col = 1;
- strcpy(DIR_display[i].label, result_spec_list[i]);
- }
- if((num_files+ROW_OFFSET) > DIR_ROWS)
- drows = DIR_ROWS;
- else
- drows = num_files + ROW_OFFSET;
- #if defined(vms)
- change_virtual_display(drows, DIR_COLUMNS, S.DIR_vid,
- BORDER, BOLD);
- #else
- change_virtual_display(drows, DIR_COLUMNS, &S.DIR_vid,
- BORDER, BOLD);
- #endif
- CDFWALK_put_message(S.MES_vid, select_mes, NOBELL, NORMAL, NOPAUSE);
- CDFWALK_Menu_keydef(screen);
- CDFWALK_select_menu_item(S.DIR_vid,
- S.MES_vid, &CDF_num, DIR_display, num_files, drows,
- DIR_COLUMNS, DIR_ROW_PASTE, DIR_COL_PASTE, MENU, &tcode);
- free (DIR_display);
- } /* end num_files > 1 */
- if(tcode == KB_RETURN)
- {
- if(dir || strlen(directory_list[CDF_num-1]) > 0)
- {
- strcpy(C.CDF_name, directory_list[CDF_num-1]);
- AppendToDir(C.CDF_name, result_spec_list[CDF_num-1]);
- }
- else
- strcpy(C.CDF_name, result_spec_list[CDF_num-1]);
-
- C.CDF_name[CDF_NAME_LENGTH]= '\0';
- CDFWALK_put_selection(S.CDF_vid, CDF_display, 0,
- C.CDF_name, CDF_NAME_LENGTH-COL_OFFSET, REVERSE);
- new_CDF = TRUE;
- *field_num = WALK_FIELD;
- }
- else
- {
- change_rendition(S.CDF_vid, CDF_NAME_ROW, CDF_NAME_COL, 1,
- strlen(C.CDF_name), REVERSE);
- if(tcode == KB_CTRL_F)
- {
- CDFWALK_field_menu(screen, field_num);
- if((int) (*field_num) == CDF_FIELD)done = FALSE;
- }
- else
- done = FALSE;
- first = TRUE;
- } /* num > 1 */
-
- free (directory_list);
- free (result_spec_list);
- } /*num_file > 0*/
- else
- {
- CDFWALK_put_message(S.MES_vid, dir_error, RINGBELL, NORMAL, PAUSE);
- first = TRUE;
- last_error = TRUE;
- }
- }/*keyboard != C-F*/
- }/*done?*/
- /*
- If a new CDF was not selected put the old one back on the input line
- */
- if(!new_CDF)
- {
- strcpy(C.CDF_name, save_name);
- CDFWALK_put_selection(S.CDF_vid, CDF_display, 0,
- C.CDF_name, CDF_NAME_LENGTH-COL_OFFSET, REVERSE);
- }
- return(tcode);
-
- }
- void CDFWALK_CDF_info(screen, CDF, CDF_display)
- struct GLOBAL_struct *screen;
- struct CDF_struct *CDF;
- struct vid_struct CDF_display[];
- {
- char string[21];
- char temp[7];
- long int i;
- sprintf(string, "%ld ", C.num_vars);
- CDFWALK_clear_row(S.CDF_vid, CDF_display, NUMVAR_ELEMENT_NUM,
- NUMVAR_ELEMENT_NUM, 27);
- CDFWALK_put_selection(S.CDF_vid, CDF_display, NUMVAR_ELEMENT_NUM-1, string,
- 6, REVERSE);
- sprintf(string, "%ld ", C.max_record_num+1);
- CDFWALK_clear_row(S.CDF_vid, CDF_display, NUMREC_ELEMENT_NUM,
- NUMREC_ELEMENT_NUM, CDF_COLUMNS-COL_OFFSET);
- CDFWALK_put_selection(S.CDF_vid, CDF_display, NUMREC_ELEMENT_NUM-1, string,
- 6, REVERSE);
- sprintf(string, "%ld ", C.num_dims);
- CDFWALK_clear_row(S.CDF_vid, CDF_display, NUMDIM_ELEMENT_NUM,
- NUMDIM_ELEMENT_NUM, CDF_COLUMNS-COL_OFFSET);
- CDFWALK_put_selection(S.CDF_vid, CDF_display, NUMDIM_ELEMENT_NUM-1, string,
- 2, REVERSE);
- string[0] = '\0';
- CDFWALK_clear_row(S.CDF_vid, CDF_display, DIMSIZ_ELEMENT_NUM,
- DIMSIZ_ELEMENT_NUM, CDF_COLUMNS-COL_OFFSET);
- if(C.num_dims > 0)
- {
- for (i=0; i < C.num_dims; i++)
- {
- sprintf(temp, "%ld ", C.dim_sizes[i]);
- strcat(string, temp);
- }
- }
- else
- string[0] = '\0';
- CDFWALK_put_selection(S.CDF_vid, CDF_display, DIMSIZ_ELEMENT_NUM-1, string,
- 10, REVERSE);
- }
- void load_vid(vid, display, start_element, num_elements, label)
- WINDOWid vid;
- struct vid_struct display[];
- int start_element;
- int num_elements;
- char label[];
- {
- long int i;
- int len;
-
- int erase_mode = NOERASE;
- int video_type = NORMAL;
- len = strlen(label);
- if(len > 0)label_border(vid, label, len);
- for(i=0; i< num_elements; i++)
- {
- len = strlen(display[i+start_element].label);
- put_chars(vid, display[i+start_element].label, len,
- display[i+start_element].row, display[i+start_element].col,
- erase_mode, video_type);
- }
- }
- void load_vid_element(vid, display, element_num)
- WINDOWid vid;
- struct vid_struct display[];
- int element_num;
- {
-
- int len;
-
- long int erase_mode = NOERASE;
- long int video_type = NORMAL;
-
- len = strlen(display[element_num-1].label);
- put_chars(vid, display[element_num-1].label, len,
- display[element_num-1].row, display[element_num-1].col, erase_mode, video_type);
- }
- void CDFWALK_load_keydef(vid, line1, line2)
- WINDOWid vid;
- char line1[];
- char line2[];
- {
- int row, col;
- int erase_mode;
- int video_type;
- int len;
-
- begin_display_update(vid);
- erase_display(vid, 1, 1, KEY_ROWS-ROW_OFFSET, KEY_COLUMNS-COL_OFFSET);
- row = 1; col = 1; erase_mode = ERASE; video_type = NORMAL;
- len = strlen(line1);
- if(len > (KEY_COLUMNS-COL_OFFSET))len = KEY_COLUMNS - COL_OFFSET;
- put_chars(vid, line1, len, row, col, erase_mode, video_type);
- len = strlen(line2);
- row = 2; col = 1; erase_mode = ERASE; video_type = NORMAL;
- if(len > (KEY_COLUMNS-COL_OFFSET))len = KEY_COLUMNS - COL_OFFSET;
- put_chars(vid, line2, len, row, col, erase_mode, video_type);
- #if defined(vms)
- end_display_update(vid);
- #else
- end_display_update_nobox(vid);
- #endif
- }
- void CDFWALK_put_selection(vid, display, element_num, selection,
- field_len, video_type)
- WINDOWid vid;
- struct vid_struct display[];
- int element_num;
- char selection[];
- int field_len;
- int video_type;
- {
- /*long int i;*/
- int len;
-
- int erase_mode = NOERASE;
- int row, col, end_col;
-
- len = strlen(display[element_num].label);
- row = display[element_num].row;
- col = display[element_num].col + len;
- len = strlen(selection);
- end_col = col + field_len - 1;
- erase_display(vid, row, col, row, end_col);
- put_chars(vid, selection, len, row, col, erase_mode, video_type);
- }
- void CDFWALK_put_value(vid, display, element_num, bin_value)
- WINDOWid vid;
- struct vid_struct display[];
- int element_num;
- double bin_value;
- {
- char value[20];
- long int i;
- int len;
-
- int erase_mode = NOERASE;
- int video_type = NORMAL;
- int row, col, end_col;
-
- len = strlen(display[element_num].label);
- row = display[element_num].row;
- col = display[element_num].col;
- end_col = col + 20;
- erase_display(vid, row, col, row, end_col);
- sprintf(value,"%f",bin_value);
- zero_replace(value);
- len = strlen(value);
- for(i = len; i<14; i++)
- value[i] = ' ';
- value[14] = '\0';
- len = 14;
- put_chars(vid, value, len, row, col, erase_mode, video_type);
- }
- void CDFWALK_put_message(vid, message, rbell, video_type, pause)
- WINDOWid vid;
- char message[];
- int rbell;
- int video_type;
- int pause;
- {
- /*long int i;*/
- int len;
-
- int erase_mode = ERASE;
- int row, col;
- #if defined(vms)
- float wait = 3.;
- #endif
-
- len = strlen(message);
- row = 1;
- col = 1;
- if(rbell == RINGBELL)
- #if defined(vms)
- ring_bell(vid);
- #else
- ring_bell();
- #endif
- if(len > (MES_COLUMNS-COL_OFFSET))len = MES_COLUMNS - COL_OFFSET;
- put_chars(vid, message, len, row, col, erase_mode, video_type);
- if(pause == PAUSE)
- #ifdef vms
- lib$wait(&wait);
- #endif
-
- #if defined(unix) | defined(ultrix) | defined(__MSDOS__)
- sleep(3);
- #endif
-
- }
- void load_menu(vid, display, num_elements, label)
- WINDOWid vid;
- struct vid_struct display[];
- int num_elements;
- char label[];
- {
- long int i;
- int len;
-
- int erase_mode = NOERASE;
- int video_type = NORMAL;
- int row;
- int col = 1;
- len = strlen(label);
- if(len > 0)label_border(vid, label, len);
- for(i=0; i< num_elements; i++)
- {
- row = i + 1;
- len = strlen(display[i].label);
- put_chars(vid, display[i].label, len, row, col,
- erase_mode, video_type);
- }
- }
- void zero_replace(string)
- char string[];
- {
- long int zero_index;
- /*long int period;*/
- long int byte /*, ebyte*/ ;
- long int found = FALSE;
- long int len;
-
- CDFWALK_left_justify(string);
- byte = 0;
- len = strlen(string);
- while(byte < len && !found)
- {
- if(string[byte] == PERIOD)found = TRUE;
- byte++;
- }
- if(found)
- {
- zero_index = byte;
- while(byte < len)
- {
- if(string[byte] == '0')
- {
- if(zero_index == 0)zero_index = byte;
- }
- else
- zero_index = 0;
- byte++;
- }
- if(zero_index > 0)
- {
- for (byte=zero_index; byte<len; byte++)
- string[byte] = ' ';
- }
- }
- }
- void CDFWALK_left_justify (field)
- char field[];
- {
- long int i;
- long int index;
- long int done;
- char *temp;
- long int len;
- len = strlen(field);
- temp = (char *) malloc(len);
-
- /* Blank out temporary hold area */
-
- for (i = 0; i < len; i++)
- temp[i] = ' ';
-
-
- done = FALSE;
- for (index = 0; done != TRUE && index <= len; index++)
-
- {
- /* Look for a non-blank character */
-
- if(field[index] != ' ')
- {
- /* Left Justify by copying from the non-blank character to the end of field */
-
- strncpy(temp,field+index,len-index);
- for (i = 0; i < len; i++)
- field[i] = ' ';
-
- /* Now copy from the temporary field back to the permanent field */
-
- strncpy(field, temp, len);
- done = TRUE;
- }
- }
- free(temp);
- }
- int precision(num)
- double num;
- {
- double abs_value;
- int p;
- abs_value = fabs(num);
- if(abs_value < 1.)
- p = 5;
- else if(abs_value < 10.)
- p = 4;
- else if(abs_value < 10000.)
- p = 3;
- else if(abs_value < 100000.)
- p = 2;
- else
- p = 1;
- return(p);
- }
- CDFstatus CDFWALK_close(CDF, variables)
- struct CDF_struct *CDF;
- struct variable_struct *variables;
- {
- CDFstatus rcode;
-
- CDFWALK_free_discrete(variables, C.num_vars);
- free(variables);
- free(C.all_dim_var_num);
- rcode = CDFclose(C.CDF_id);
- return(rcode);
- }
- void CDFWALK_close_screen()
- {
- delete_pasteboard(ERASE);
- }
- double r4_r8(r4_ptr)
- float *r4_ptr;
- {
- /*
- Convert float to double
- Based on assumption that float contains 7 significant digits
- */
- float r4;
- double r4r8;
- double fracr8;
- float realexp,temp,rfrac,x;
- double base, power;
- long int /*itemp,*/ exp,frac;
- long int evalue;
-
- r4 = *r4_ptr;
- /*
- If the REAL*4 value is 0 then just set the REAL*8 value to 0 and return
- */
- if(r4 == 0.) return(0.);
-
- temp = r4;
- evalue = 0;
- /*
- Calculate the exponent of the incoming REAL*4 value
- If absolute value ge 10 exponent is positive
- If absolute value lt 1 exponent is negative
- */
- if(fabs(temp) >= 10.)
- {
- while(fabs(temp) >= 10.)
- {
- evalue = evalue + 1;
- temp = temp / 10.;
- }
- }
- else if(fabs(temp) < 1.)
- {
- while(fabs(temp) < 1.)
- {
- evalue = evalue - 1;
- temp = temp * 10.;
- }
- }
- /*
- Extract out the fractional portion of the real value
- */
- exp = (long int) r4;
- realexp = (float) exp;
- rfrac = r4-realexp;
- /*
- Convert significant digits of fraction portion to integer by multiplying.
- */
- base = 10.;
- power = (double) (6-evalue);
- x = rfrac*pow(base,power);
- if(x > 0.)
- frac = (long int) (x + .5);
- else
- frac = (long int) (x - .5);
- fracr8 = (double) frac;
- r4r8 = (double) exp;
- /*
- Convert the integer back into a fraction by diving.
- then ADD back in the integer portion.
- */
- r4r8 = r4r8 + fracr8/(pow(base, power));
- return(r4r8);
- }
- long int CDFWALK_get_index(CDF_id, dim_num, var_num, value, data_type,
- dim_values, num_values)
- long int CDF_id;
- long int dim_num;
- long int var_num;
- long int data_type;
- double value;
- double dim_values[];
- long int num_values;
- {
- long int i;
- double diff,closest_diff;
- long int closest_indice;
- double min,max,fudge_up,fudge_down;
- long int indices[10];
- long int record_num;
- CDFstatus rcode;
- double test_value;
- union mixed temp;
- double r4_r8();
-
-
- if(data_type != CDF_REAL8 && data_type != CDF_EPOCH)
- {
- fudge_down = .999999; fudge_up = 1.000001;
- if(value > 0.)
- {
- min = fudge_down*value;
- max = fudge_up*value;
- }
- else
- {
- min = fudge_up*value;
- max = fudge_down*value;
- }
- }
- else
- {
- min = value;
- max = value;
- }
- if(num_values > MAX_VALUES)
- {
- record_num = 0;
- for (i=0; i < CDF_MAX_DIMS; i++)
- indices[i] = 0;
- }
- closest_diff = 1.7e38;
- closest_indice = 0;
- for(i=0; i<num_values; i++)
- {
- if(num_values > MAX_VALUES)
- {
- if(dim_num > 0)
- indices[dim_num-1]=i;
- else
- record_num = i;
- switch(data_type)
- {
- case CDF_REAL4:
- case CDF_FLOAT:
- rcode = CDFvarGet(CDF_id, var_num, record_num,
- indices, &temp.r4);
- test_value = r4_r8(&temp.r4);
- break;
- case CDF_REAL8:
- case CDF_DOUBLE:
- case CDF_EPOCH:
- rcode = CDFvarGet(CDF_id, var_num, record_num,
- indices, &temp.r8);
- test_value = temp.r8;
- break;
- case CDF_INT4:
- rcode = CDFvarGet(CDF_id, var_num, record_num,
- indices, &temp.i4);
- test_value = (double) temp.i4;
- break;
- case CDF_UINT4:
- rcode = CDFvarGet(CDF_id, var_num, record_num,
- indices, &temp.ui4);
- test_value = (double) temp.ui4;
- break;
- case CDF_INT2:
- rcode = CDFvarGet(CDF_id, var_num, record_num,
- indices, &temp.i2);
- test_value = (double) temp.i2;
- break;
- case CDF_UINT2:
- rcode = CDFvarGet(CDF_id, var_num, record_num,
- indices, &temp.ui2);
- test_value = (double) temp.ui2;
- break;
- case CDF_BYTE:
- case CDF_INT1:
- rcode = CDFvarGet(CDF_id, var_num, record_num,
- indices, &temp.byte);
- test_value = (double) temp.byte;
- break;
- case CDF_UINT1:
- rcode = CDFvarGet(CDF_id, var_num, record_num,
- indices, &temp.ubyte);
- test_value = (double) temp.ubyte;
- }
- if(rcode < CDF_OK)test_value = 1.7e38;
- }
- else
- test_value = dim_values[i];
- if(test_value >= min && test_value <= max)return(i);
- diff = fabs(test_value - value);
- if(diff < closest_diff)
- {
- closest_diff = diff;
- closest_indice = i;
- }
- }
- return(closest_indice);
- }
- long int CDFWALK_get_index_char(CDF_id, dim_num, var_num, value,
- num_bytes, dim_values, num_values)
- long int CDF_id;
- long int dim_num;
- long int var_num;
- char *value;
- long int num_bytes;
- char dim_values[];
- long int num_values;
- {
- long int i;
- long int closest_indice;
- long int most;
- long int num;
- long int indices[CDF_MAX_DIMS];
- long int record_num;
- CDFstatus rcode;
- char *string;
-
- closest_indice = 0;
- most = 0;
-
- string = (char *) malloc(num_bytes+1);
- if(string == NULL)return(closest_indice);
- if(num_values > MAX_VALUES)
- {
- record_num = 0;
- for (i=0; i < CDF_MAX_DIMS; i++)
- indices[i] = 0;
- }
-
-
- for(i=0; i<num_values; i++)
- {
- if(num_values > MAX_VALUES)
- {
- if(dim_num > 0)
- indices[dim_num-1]=i;
- else
- record_num = i;
-
- rcode = CDFvarGet(CDF_id, var_num, record_num, indices,
- string);
- if(rcode < CDF_OK)
- string[0] = '\0';
- else
- string[num_bytes] = '\0';
- }
- else
- strcpy( string, &dim_values[i*(num_bytes+1)]);
- num = how_many_match(value, string);
- if(num > most)
- {
- closest_indice = i;
- most = num;
- }
- }
- free(string);
- return(closest_indice);
- }
- void make_it_upper(upstring,string)
- char *upstring;
- char *string;
- {
- int i,len;
- len=strlen(string);
- for(i=0; i<len; i++)
- {
- upstring[i] = (islower(string[i]) ?
- toupper(string[i]) : string[i]);
- }
- }
- long int how_many_match(str1, str2)
- char *str1;
- char *str2;
- {
- char *up1, *up2;
- long int num,i;
- up1 = (char *) malloc(strlen(str1) + 1);
- up2 = (char *) malloc(strlen(str2) + 1);
- make_it_upper(up1, str1);
- make_it_upper(up2, str2);
- for(i=0, num=0; up1[i] == up2[i] && up1[i] != '\0'; i++)
- num++;
- free(up1);
- free(up2);
- return(num);
- }
- long int check_epoch(str, scale)
- char str[];
- double *scale;
- {
- static char default_time[] = " 00:00:00.000";
- long int len;
- long int rcode;
- *scale = 0.;
- len = strlen(str);
- if(len == 0)
- return(TRUE);
- else if(len < 11)
- return(FALSE);
- else if(len < 24)
- strcat(str, default_time+(len+2-13));
- rcode = epochParse(str, &ep);
- *scale = ep.tSince0;
- return(rcode);
- }
- void CDFWALK_free_discrete(variables, num_vars)
- struct variable_struct variables[];
- long int num_vars;
- {
- long int var_num;
- for(var_num = 0; var_num < num_vars; var_num++)
- {
- if(V.bin_value != NULL)free(V.bin_value);
- if(V.char_value != NULL)free(V.char_value);
- }
- }
-
-